<?php

namespace app\model;
use think\Model;

class File extends Model
{
    public static function getRemoteSize($file)
    {

        ob_start();
        $ch = curl_init($file);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, 1);

        $ok = curl_exec($ch);
        curl_close($ch);
        $head = ob_get_contents();
        ob_end_clean();

        $regex = '/Content-Length:\s([0-9].+?)\s/';
        $count = preg_match($regex, $head, $matches);

        return sprintf("%.2f",$matches[1]/1000000) ?? 0;
    }



}